<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('nickname');
            $table->string('email')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->string('telephone', 32);
            $table->string('avatar')->nullable();
            $table->string('type', 32);
            $table->bigInteger('store_id');
            $table->dateTime('last_login_time')->nullable();
            $table->string('status', 32);
            $table->string('remark')->nullable();
            $table->string('code', 32)->nullable();
            $table->string('parent_user_id', 32)->nullable();
            $table->bigInteger('role_id');
            $table->softDeletes();
            $table->rememberToken();
            $table->timestamps();
        });

        //创建管理员
        \App\Models\User::create([
            'name' => '超级管理员',
            'nickname' => '超级管理员',
            'password' => \Illuminate\Support\Facades\Hash::make('admin'),
            'telephone' => 'admin',
            'type' => \App\Enums\UserType::System->value,
            'store_id' => 0,
            'status' => \App\Enums\UserStatus::Normal,
            'remark' => '超级管理员无法删除',
            'code' => 'admin',
            'role_id' => 0,
            'parent_user_id' => 0,
        ]);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('users');
    }
};
